/*
 * @Author: 肖思汗 
 * @Date: 2025-06-11 09:42:13 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-08-14 16:28:09
 */

import Api from "src/api/Api";
import { GoodsData, ShopCarData } from "types/type";

//购物车接口模版
class ShoppingCartApi extends Api {

    constructor() {
        super();
    }

    // 获取购物车列表
    getList(pageNum: number = 1, pageSize: number = 10) {
        return this._get("/appUserShopCart/list", { pageNum, pageSize });
    }

    // 添加购物车
    add(shopCarData: {
        productId: number, // 商品id
        productNegativeId: number, // 底板id
        productDesign: GoodsData["productData"],// 具体商品设计json
        designName: string,
        productShowImageUrl: string, // 商品图片
        size: string, // 规格
        color?: string // 颜色
        addToDesign: boolean, // 是否添加到设计
    }) {
        //@ts-ignore
        shopCarData.productDesign = JSON.stringify(shopCarData.productDesign);
        return this._post("/appUserShopCart/addShopCart", shopCarData);
    }

    //编辑
    edit(shopCarData: ShopCarData) {
        return this._post("/appUserShopCart/editShopCart", shopCarData);
    }

    // 修改购物车商品的数量
    changeProductNumber(shopCartId: number, productNumber: number) {
        return this._get("/appUserShopCart/changeProductNumber", { shopCartId, productNumber });
    }


    // 修改购物车商品规格
    changeProductSize(shopCartId: number, productSize: string) {
        return this._get("/appUserShopCart/changeProductSize", { shopCartId, productSize });
    }

    // 删除购物车商品
    delete(shopCartIds: string) {
        return this._get(`/appUserShopCart/batchDelete/${shopCartIds}`);
    }

    // 复制购物车
    copyShopCart(shopCartId: number) {
        return this._get(`/appUserShopCart/copyShopCart/${shopCartId}`);
    }

    // 根据购物车id计算总价格
    caculateProductPrice(shopCartIds: string) {
        return this._get(`/appUserShopCart/caculateProductPrice/${shopCartIds}`);
    }

}

const shoppingCartApi = new ShoppingCartApi();

export default shoppingCartApi;